package com.wanmait.shoppingsys.controller.manage;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.wanmait.shoppingsys.dao.ManageDAO;
import com.wanmait.shoppingsys.dao.UserinfoDAO;
import com.wanmait.shoppingsys.util.ManagePager;

@WebServlet("/UserinfoManageController")
public class UserinfoManageController extends HttpServlet
{
	 private ManageDAO manageDAO=new ManageDAO();
		protected void doPost(HttpServletRequest request, HttpServletResponse response)
				throws ServletException, IOException {
			doGet(request, response);
		}
		
		protected void doGet(HttpServletRequest request, HttpServletResponse response)
				throws ServletException, IOException {
		 request.setCharacterEncoding("UTF-8");
		 String action=request.getParameter("action");
		 if(action==null)
		 {
			 return;
		 }
		 switch(action) {
		 case "userinfodelete":   //用户物理删除
			 this.userinfodelete(request, response);
				break;
		 case "userinfolist":    //用户列表
			 this.userinfolist(request, response);
			 break;
		 case "delete1":       //逻辑删除  恢复
			 this.delete1(request, response);
			 break;
		    }
		}
		
		
		protected void delete1(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
		 {
			 String idStr = request.getParameter("id");
			 Integer id = Integer.parseInt(idStr);
			 String enStr = request.getParameter("en");
			 Integer en = Integer.parseInt(enStr);
			 UserinfoDAO.getDAO().update(id,en);
		 }
		protected void userinfodelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
			String userinfoId = request.getParameter("userinfoId");
			Integer id = Integer.parseInt(userinfoId);
			manageDAO.deleteUserinfo(id);
			this.userinfolist(request, response);
		}
		protected void userinfolist(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
			ManagePager managepager = ManagePager.init(request);
			manageDAO.findAll5(managepager);
			request.getRequestDispatcher("/manage/userinfolist.jsp").forward(request, response);
		 }
}
